// pages/user/user.js
var app = getApp()
Page( {
  data: {
    userInfo: {},
    orderInfo:{},
    loadingText: '加载中...',
    loadingHidden: false,
    money:[],
  },
  onLoad: function () {
    
    wx.setNavigationBarColor({
      frontColor: '#ffffff', // 必写项
      backgroundColor: '#FE9D4E', // 必写项
      animation: { // 可选项
        duration: 400,
        timingFunc: 'easeIn'
      }
    });

      var that = this
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function(userInfo){
        //更新数据
        that.setData({
          userInfo:userInfo,
          loadingHidden: true
        });
      });
    if (app.globalData.phone && app.globalData.phone != '') {
      that.setData({
        phone: app.globalData.phone,
      });
    }

    //if (that.data.phone.length != 11 || that.data.vip == 0) {
    if (that.data.phone == undefined || that.data.vip == 0) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.phoneCallback = phone => {
        if (phone != '') {
          that.setData({
            phone: phone,
          });
        }
      }

      app.receiveCallback = receive => {
        that.setData({
          receive: receive,
        });
      }
    }
    //console.log(that.data.phone);
    //console.log(that.data.vip);
    this.loadOrderStatus();
  },
  onShow: function () {
    
    this.loadOrderStatus2();
  },
  wanshan:function(){
    wx.showModal({
      title: '赚钱那些事儿',
      content: '您还未完善银行卡信息，暂不能提现，现在去完善？',
      success(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '../user/company',
          })
        } else if (res.cancel) {

        }
      }
    })
  },
  loadOrderStatus:function(){
    //获取用户订单数据
    var that = this;

    wx.request({
      url: app.d.hostUrl + 'wapi/user_order.html',
      method:'post',
      data: {
        seesionid: app.globalData.userInfo.sessionId,
        openid: app.globalData.userInfo.openid,
      },
      header: {
        'Content-Type':  'application/x-www-form-urlencoded'
      },
      success: function (res) {
        //--init data        
        var status = res.data.ret;
        if(status == 0){
          var orderInfo = res.data.data;
          that.setData({
            orderInfo: orderInfo
          });
        }else{
          /**wx.showToast({
            title: '非法操作.',
            duration: 2000
          });**/
        }
      },
      error:function(e){
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    });
  },
  loadOrderStatus2: function () {
    //获取用户订单数据
    var that = this;

    wx.request({
      url: app.d.hostUrl + 'wapi/user_order.html',
      method: 'post',
      data: {
        seesionid: app.globalData.userInfo.sessionId,
        openid: app.globalData.userInfo.openid,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        //--init data        
        var status = res.data.ret;
        if (status == 0) {
          /**var orderInfo = res.data.data;
          if (orderInfo.bank == '') {
            wx.showModal({
              title: '极好生活提示',
              content: '您还未完善用户信息，将影响提现，现在去完善？',
              success(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '../user/company',
                  })
                } else if (res.cancel) {

                }
              }
            })
          }
          that.setData({
            orderInfo: orderInfo
          });**/
        } else {
          /**wx.showToast({
            title: '非法操作.',
            duration: 2000
          });**/
        }
      },
      error: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    });
  },
  onShareAppMessage: function () {
    return {
      title: '赚钱那些事儿',
      path: '/pages/index/index?scene=invite%3D' + app.globalData.user_id,
      success: function (res) {
        wx.showToast({
          title: '分享成功',
          duration: 2000
        });
      },
      fail: function (res) {
        // 分享失败
      }
    }
  },
})